package tmproject.hlhj.fhp.anwser.http

import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response
import com.lzy.okrx.adapter.ObservableResponse
import rx.Observable
import rx.schedulers.Schedulers
import tmproject.hlhj.fhp.anwser.bean.*

/**
 * Created by Never Fear   on 2018\8\21 0021.
Never More....
 */
object Apis {

    fun sendSms(mobile:String): Observable<Response<SmsBean>>? {
        return OkGo.post<SmsBean>(Urls.BaseUrl+Urls.SendSMS)
                .params("mobile",mobile)
                .converter(object :JsonConvert<SmsBean>(){})
                .adapt(ObservableResponse<SmsBean>())
                .subscribeOn(Schedulers.io())
    }

    fun login(mobile:String,sms_code:String): Observable<Response<LoginBean>>? {
     return   OkGo.post<LoginBean>(Urls.BaseUrl+Urls.Login)
                .params("mobile",mobile)
                .params("sms_code",sms_code)
                .converter(object :JsonConvert<LoginBean>(){})
                .adapt(ObservableResponse<LoginBean>())
                .subscribeOn(Schedulers.io())
    }

    fun getActiveList(status:Int): Observable<Response<ActiveBean>>? {
       return OkGo.get<ActiveBean>(Urls.BaseUrl+Urls.Active_List)
               .params("status",status)
                .converter(object :JsonConvert<ActiveBean>(){})
                .adapt(ObservableResponse<ActiveBean>())
                .subscribeOn(Schedulers.io())
    }

    fun getActiveDetail(activity_id:Int,token:String): Observable<Response<ActiveDetailBean>>? {
       return OkGo.get<ActiveDetailBean>(Urls.BaseUrl+Urls.Active_Detail)
                .params("activity_id",activity_id)
               .params("token",token)
                .converter(object :JsonConvert<ActiveDetailBean>(){})
                .adapt(ObservableResponse<ActiveDetailBean>())
                .subscribeOn(Schedulers.io())
    }
    fun getUserInfo(token:String): Observable<Response<UserInfoBean>>? {
        return OkGo.get<UserInfoBean>(Urls.BaseUrl+Urls.Get_User_Info)
                .params("token",token)
                .converter(object :JsonConvert<UserInfoBean>(){})
                .adapt(ObservableResponse<UserInfoBean>())
                .subscribeOn(Schedulers.io())
    }

    fun commitAnwser(activity_id:Int,corrent_count:Int,token:String): Observable<Response<BaseBean>> {
        return OkGo.post<BaseBean>(Urls.BaseUrl+Urls.CommitAnwser)
                .headers("token",token)
                .params("activity_id",activity_id)
                .params("correct_count",corrent_count)
                .converter(object :JsonConvert<BaseBean>(){})
                .adapt(ObservableResponse<BaseBean>())
                .subscribeOn(Schedulers.io())
    }
    fun getPrize(): Observable<Response<PrizeBean>>? {
       return  OkGo.get<PrizeBean>(Urls.BaseUrl+Urls.Prize)
                .converter(object :JsonConvert<PrizeBean>(){})
                .adapt(ObservableResponse<PrizeBean>())
                .subscribeOn(Schedulers.io())
    }
}